package com.example.designpatterns.behavioral.chain;

/**
 * 具体处理者：校验用户有效性
 *
 * @author scott
 */
public class UserExistsMiddleware extends Middleware {

    private final Server server;

    public UserExistsMiddleware(Server server) {
        this.server = server;
    }

    @Override
    public boolean check(String email, String password) {
        if (!server.hasEmail(email)) {
            System.out.println("用户不存在。");
            return false;
        }
        if (!server.isValidPassword(email, password)) {
            System.out.println("密码错误。");
            return false;
        }
        return checkNext(email, password);
    }
}
